package forum;

import java.util.ArrayList;

public class Member {
	private String username;
	private String firstName;
	private String lastName;
	private boolean status; //true - logged in, flase - logged off
	private String role; //member or moderator
	private String email;
	private String gender; //m or f
	private ArrayList<String> friends;
	
	public Member (String uName, String fName, String lName, String mail, String g){
		this.username = uName;
		this.firstName = fName;
		this.lastName = lName;
		this.status = false;
		this.role = "member";
		this.email = mail;
		this.gender = g;
		this.friends = new ArrayList<String>();
	}
	
	/**
	 * This method changes the status of the member to true, so he is logged in
	 */
	public void login(){
		this.status = true;
	}
	
	/**
	 * This method changes the status of the member to false, so he is logged off
	 */
	public void logoff(){
		this.status = false;
	}
	
	/**
	 * This method adds a specified friend to the friends' list
	 * @param friendName: the name of the friend to add
	 * @return true if the adding was successful and false otherwise 
	 * 		(if the friend already exists in the user's friends' list).
	 */
	public boolean addFriend(String friendName){
		int indexOfFriend = this.findFriend(friendName);
		if (indexOfFriend >= 0)
			return false;
		return this.friends.add(friendName);
	}
	
	/**
	 * This method removes the specified friend
	 * @param friendName:  the name of the friend to remove
	 * @return the name of the removed friend 
	 * 		   or an empty string if the friend is not in the list.
	 */
	public String removeFriend(String friendName){
		int index = findFriend(friendName);
		if (index != -1)
			return this.friends.remove(index);
		return "";
	}

	//This method looks for a name of friend in the friends' list.
	//If the friend isn't fount then the method returns -1
	//else the method return the place of the friend
	private int findFriend(String friendName) {
		for (int i = 0; i < this.friends.size(); i++)
			if (this.friends.get(i).equalsIgnoreCase(friendName))
				return i;
		return -1;
	}
	
	public void setModeratorRole(){
		this.role = "moderator";
	}
	
	public void setMemberRole(){
		this.role = "member";
	}

	public String getUsername() {
		return this.username;
	}
	
	public String getFirstName() {
		return this.firstName;
	}
	
	public String getLastName() {
		return this.lastName;
	}
	
	public boolean getStatus() {
		return this.status;
	}
	
	public String getRole(){
		return this.role;
	}
	
	public String getEMail() {
		return this.email;
	}
	
	public String getGender() {
		return this.gender;
	}

	public ArrayList<String> getFriends() {
		return this.friends;
	}
	
	
	
}
